<%--
    Document   : cadastro
    Created on : 07/10/2011, 22:21:28
    Author     : Carlos, Edward, Diego, Honorio
--%>

<%@page import="controller.Controlador"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page isThreadSafe="false"%>  <!-- false nao permite executar threads ao mesmo tempo-->
<%! int j;%>
<%! int i = ((int) Math.random()) + (int) (Math.random() * 1000);%>
<% j = i++;%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="style.css" type="text/css" media="screen">
        <title>CADASTRO DE USUARIO</title>
    </head>

    <jsp:include page="topo.jsp"/>
    <body >


        <div id="content">
            <br><br><br>
            <center><img src="imagens/clientes.jpg"></center>


            <!--<form action="/AirLine/controlador?cmd=salvarUser" method="post">-->
            <form action="/AirLine/cadastro.jsp?cmd=salvarUser" method="post">
                <table style="text-align: left; width: 90%;" border="0" cellpadding="2" cellspacing="2">
                    <tbody>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">ID: </td>
                            <td style="vertical-align: top;"><input type="text" name="id" value="<%= i%>" readonly="true"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Nome: </td>
                            <td style="vertical-align: top;"><input type="text" name="nome" ></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Telefone: </td>
                            <td style="vertical-align: top;"><input type="text" name="telefone"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">CPF: </td>
                            <td style="vertical-align: top;"><input type="text" name="cpf"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">E-mail: </td>
                            <td style="vertical-align: top;"><input type="text" name="email"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Login: </td>
                            <td style="vertical-align: top;"><input type="text" name="login"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Senha: </td>
                            <td style="vertical-align: top;"><input type="password" name="senha"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top; text-align: right;">Confirme a Senha: </td>
                            <td style="vertical-align: top;"><input type="password" name="senhaconf"></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><input type="submit" value="Cadastrar">
                                <input type="reset" value="Limpar"></td>
                        </tr>
                    </tbody>
                </table>
            </form>

            <%


            //CRIADOR DE COOKIES
            Cookie cookie= new Cookie("usuario", request.getParameter("nome")); //cria o cookie de nome usuario, e coloca nele o valor do usuario do formulário
            cookie.setMaxAge(60 * 60 * 24 * 30); //define o tempo de vida do cookie para 1 mes
            response.addCookie(cookie);
            //FIM DOS COOKIES


                String id = request.getParameter("id");
                String nome = request.getParameter("nome");
                String cpf = request.getParameter("cpf");
                String telefone = request.getParameter("telefone");
                String email = request.getParameter("email");
                String login = request.getParameter("login");
                String senha = request.getParameter("senha");
                String senhaconf = request.getParameter("senhaconf");
                String cmd = request.getParameter("cmd");
                boolean test = true;

                if (cmd != null && cmd != "") {
                    if (nome == null || nome == "") {
                        out.print("<font color = red><h4><center>Nome inválido!</h4></center></font>");
                        test = false;
                    }
                    if (cpf == null || cpf == "") {
                        out.print("<font color = red><h4><center>CPF inválido</h4></center></font>");
                        test = false;
                    }
                    if (telefone == null || telefone == "") {
                        out.print("<font color = red><h4><center>Telefone inválido</h4></center></font>");
                        test = false;
                    }
                    if (email == null || email == "") {
                        out.print("<font color = red><h4><center>E-mail inválido</h4></center></font>");
                        test = false;
                    }
                    if (login == null || login == "") {
                        out.print("<font color = red><h4><center>Login inválido<h4><center></font>");
                        test = false;
                    }
                    if (senha == null || senha == "") {
                        out.print("<font color = red><h4><center>Confirmação de senha inválida</h4></center></font>");
                        test = false;
                    }
                    if (!senha.equalsIgnoreCase(senhaconf)) {
                        out.print("<font color = red><h4><center>Confirmação de senha inválida<h4><center></font>");
                        test = false;
                    }
                    if (test == true) {
            %>
        </div>
        
        <jsp:forward page="controlador" >
            <jsp:param name="cmd" value="<%=cmd%>"/>
            <jsp:param name="id" value="<%=id%>"/>
            <jsp:param name="nome" value="<%=nome%>"/>
            <jsp:param name="cpf" value="<%=cpf%>"/>
            <jsp:param name="telefone" value="<%=telefone%>"/>
            <jsp:param name="email" value="<%=email%>"/>
            <jsp:param name="login" value="<%=login%>"/>
            <jsp:param name="senha" value="<%=senhaconf%>"/>
            <jsp:param name="senhaconf" value="<%=senhaconf%>"/>
        </jsp:forward>

        <%}
                }%>



    </body>


    <jsp:include page="rodape.jsp"/>
</html>
